#
# @lc app=leetcode.cn id=504 lang=python
#
# [504] 七进制数
#

# @lc code=start
class Solution(object):
    def convertToBase7(self, num):
        """
        :type num: int
        :rtype: str
        """
        if num == 0:
            return '0'
    
        result = ''
        negative = num < 0
        num = abs(num)
        
        while num:
            result = str(num % 7) + result
            num //= 7
        
        return ('-' if negative else '') + result
# @lc code=end

